home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
4490
/
4490.xpi
/
chrome
/
wmn.jar
/
content
/
wmn-overlay.js
< prev
next >
Wrap
Text File
|
2010-01-27
|
8KB
|
195 lines
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is WebMail Notifier.
*
* The Initial Developer of the Original Code is
* Byungwook Kang.
* Portions created by the Initial Developer are Copyright (C) 2007
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
const dout=Components.utils.reportError;
var wmnSb={
init:function(){
var tree=document.getElementById("placesList").lastChild;
while(tree.firstChild != null)tree.removeChild(tree.firstChild);
var n=this.nsIWebMailNotifier.getAccountsNumber();
for(var i=0;i<n;i++){
if(!this.nsIWebMailNotifier.isAccountEnabled(i))continue;
var ar=this.nsIWebMailNotifier.getAccountInfo({},i);
var o={host:ar[0],user:ar[1],ind:i};
if(this.nsIWebMailNotifier.getAccountsInHost(o.host)==1){
var em=this.createItem(this.nsIWebMailNotifier.getHostName(o.host),o.ind);
em.firstChild.firstChild.setAttribute("src",this.nsIWebMailNotifier.getIconURL(o.host,o.user));
em.setAttribute("newMail",false);
tree.appendChild(em);
}else{
var hostEm=document.getElementById(escape(o.host));
if(!hostEm){
hostEm=this.createItem(this.nsIWebMailNotifier.getHostName(o.host),escape(o.host),true);
hostEm.firstChild.firstChild.setAttribute("src",this.nsIWebMailNotifier.getIconURL(o.host,o.user));
tree.appendChild(hostEm);
hostEm=hostEm.lastChild;
}
var em=this.createItem(o.user,o.ind);
em.setAttribute("newMail",false);
hostEm.appendChild(em);
}
}
if(typeof(onWinLoad)!="undefined")onWinLoad();
},
createItem:function(label,id,isContainer){
var tc=document.createElement("treecell");
tc.setAttribute("label",label);
var tr=document.createElement("treerow");
tr.appendChild(tc);
var tc2=document.createElement("treecell");
if(!isContainer){
tc.setAttribute("properties","label logoff");
tc.setAttribute("id","lb"+id);
//tc.setAttribute("src","http://webmailnotifier.mozdev.org/favicon.ico");
tc2.setAttribute("label","");
tc2.setAttribute("properties","logoff");
tc2.setAttribute("id",id);
tc2.setAttribute("value",id);
}
tr.appendChild(tc2);
var ti=document.createElement("treeitem");
ti.appendChild(tr);
if(isContainer){
ti.setAttribute("container",true);
ti.setAttribute("open",true);
var tch=document.createElement("treechildren");
tch.setAttribute("id",id);
ti.appendChild(tch);
}else{
ti.setAttribute("id","cnt"+id);
tc.setAttribute("value",id);
}
return ti;
},
onTreeClicked: function(event){
// right-clicks are not handled here
if (event.button == 2)
return;
var tree = document.getElementById("placesList");
var tbo = tree.treeBoxObject;
var row = { }, col = { }, child = { };
tbo.getCellAt(event.clientX, event.clientY, row, col, child);
if (row.value == -1 || child.value == "twisty")return;
var val = tree.view.getCellValue(row.value, col.value);
if(val){
if(val.indexOf("fd")==0){//folder
var fnd=val.match(/fd(\d+)-/);
if(fnd){
if(col.value.id=="col0"){
this.nsIWebMailNotifier.openMail(fnd[1],document.getElementById("lb"+val).getAttribute("label"));
}else this.nsIWebMailNotifier.checkMail(fnd[1]);
}
}else{
if(col.value.id=="col0")this.nsIWebMailNotifier.openMail(val,null);
else this.nsIWebMailNotifier.checkMail(val);
}
}
},
onStateChange: function(aIndex,aCount,aData){
//dout(aIndex+" "+aCount+" "+aData);
// var ar=wmn.nsIWebMailNotifier.getAccountInfo({},aIndex);
//dout(ar);
if(aIndex==Components.interfaces.nsIWebMailNotifier.ST_INIT){
this.init();
return;
}else if(aIndex==Components.interfaces.nsIWebMailNotifier.ST_SHOWICON){
return;
}else if(aIndex==Components.interfaces.nsIWebMailNotifier.ST_RESET){//accounts change
this.init();
return;
}
var em=document.getElementById(aIndex);
var obj=decodeObject(aData);
em.setAttribute("label",obj.desc);
var em2=document.getElementById("lb"+aIndex);
var prop=aCount>0?"newMail":(aCount==0?"noMail":"logoff");
em.setAttribute("properties",prop);
em2.setAttribute("properties","label "+prop);
em.parentNode.setAttribute("properties",prop);//treerow
var ti=document.getElementById("cnt"+aIndex);//container
if(ti.childNodes.length>1){
var tr=ti.firstChild;
while(ti.firstChild) {
ti.removeChild(ti.firstChild);
}
ti.appendChild(tr);
}
if(obj.folders){
ti.setAttribute("container",true);
ti.setAttribute("open",true);
var tch=document.createElement("treechildren");
ti.appendChild(tch);
var ar=decodeArray(obj.folders);
for(var i=0;i<ar.length;i+=2){
var ind="fd"+aIndex+"-"+parseInt(i/2)
var em=this.createItem(ar[i],ind);
//em.firstChild.setAttribute("properties","noSelect");
tch.appendChild(em);
var tc=document.getElementById(ind);
tc.setAttribute("label",ar[i+1]);
//tc.setAttribute("properties","noSelect");
}
}else{
ti.removeAttribute("container");
}
},
openMails: function(aEvent){
if(aEvent && (aEvent.button==1 || (aEvent.button==0&&aEvent.shiftKey))){
this.nsIWebMailNotifier.openNewWindow();
return;
}
var openAll=aEvent && (aEvent.button == 0&&(aEvent.altKey||aEvent.metaKey));
this.nsIWebMailNotifier.openMails(openAll);
}
}
function startup() {
try {
wmnSb.nsIWebMailNotifier = Components.classes["@mozilla.org/WebMailNotifier;1"]
.getService(Components.interfaces.nsIWebMailNotifier);
wmnSb.nsIWebMailNotifier.addListener(wmnSb);
} catch (e){
dout(e);
}
}
function shutdown() {
wmnSb.nsIWebMailNotifier.removeListener(wmnSb);
}
window.addEventListener("load", startup, false);
window.addEventListener("unload", shutdown, false);